vulkan: Add clip.vert.glsl
authorBenjamin Otte <otte@redhat.com>
Tue, 17 Jan 2017 04:50:52 +0000 (05:50 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Jan 2017 05:17:55 +0000 (06:17 +0100)
Implement clipping the same way as in the last commit for the
fragment shaders.

24 files changed:
gsk/Makefile.am
gsk/resources/vulkan/blend-clip-rounded.vert.glsl
gsk/resources/vulkan/blend-clip-rounded.vert.spv
gsk/resources/vulkan/blend-clip.vert.glsl
gsk/resources/vulkan/blend-clip.vert.spv
gsk/resources/vulkan/border-clip-rounded.vert.glsl
gsk/resources/vulkan/border-clip-rounded.vert.spv
gsk/resources/vulkan/border-clip.vert.glsl
gsk/resources/vulkan/border-clip.vert.spv
gsk/resources/vulkan/clip.vert.glsl [new file with mode: 0644]
gsk/resources/vulkan/color-clip-rounded.vert.glsl
gsk/resources/vulkan/color-clip-rounded.vert.spv
gsk/resources/vulkan/color-clip.vert.glsl
gsk/resources/vulkan/color-clip.vert.spv
gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl
gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv
gsk/resources/vulkan/color-matrix-clip.vert.glsl
gsk/resources/vulkan/color-matrix-clip.vert.spv
gsk/resources/vulkan/linear-clip-rounded.vert.glsl
gsk/resources/vulkan/linear-clip-rounded.vert.spv
gsk/resources/vulkan/linear-clip.vert.glsl
gsk/resources/vulkan/linear-clip.vert.spv
gsk/resources/vulkan/linear.vert.glsl
gsk/resources/vulkan/linear.vert.spv

index dd480bfa4ea8e9b31aa9711e00c20ca2622c61a9..06ed18e97e69e3eb52d1dc93a078a28d57c05a44 100644 (file)
@@ -59,6 +59,7 @@ gsk_private_vulkan_source_c = \
        gskvulkanshader.c
 gsk_private_vulkan_include_shaders = \
        resources/vulkan/clip.frag.glsl \
+       resources/vulkan/clip.vert.glsl \
        resources/vulkan/constants.glsl \
        resources/vulkan/rounded-rect.glsl
 gsk_private_vulkan_shaders = \
index 0a5f31d79c0e3421cdfabac345421d0889be934a..fadf4b924781bcf243c5ebf6174460bce1b22cea 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
 
 layout(location = 0) in vec4 inRect;
 layout(location = 1) in vec4 inTexRect;
@@ -19,18 +20,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
                     vec2(1.0, 0.0),
                     vec2(1.0, 1.0) };
 
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
 void main() {
-  vec4 rect = intersect(inRect, push.clip_bounds);
+  vec4 rect = clip (inRect);
   vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
 
index bc82237ef54a94f68d8cd50bd23535ae82208470..cb6a9dadbbc3ffd4df85a5b174b2ad84f3807f08 100644 (file)
Binary files a/gsk/resources/vulkan/blend-clip-rounded.vert.spv and b/gsk/resources/vulkan/blend-clip-rounded.vert.spv differ
index b1c622bea28ea9df1815277ece1f05e787ff1ad6..88ad7c75e6b0d42ad3d73187a0203efe7dd8f307 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
 
 layout(location = 0) in vec4 inRect;
 layout(location = 1) in vec4 inTexRect;
@@ -18,18 +19,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
                     vec2(1.0, 0.0),
                     vec2(1.0, 1.0) };
 
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
 void main() {
-  vec4 rect = intersect(inRect, push.clip_bounds);
+  vec4 rect = clip (inRect);
   vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
 
index 494f9165373308adaa2da2b368609d0bfd8aa489..c8840cd5b8821c529c669a012918082c7241ec6c 100644 (file)
Binary files a/gsk/resources/vulkan/blend-clip.vert.spv and b/gsk/resources/vulkan/blend-clip.vert.spv differ
index 8db91a58a4b48ace963eba702f98cf77d604f9d8..ed11255ad5e2cbc9ef35a19dd4f5edce16d64df6 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
 
 layout(location = 0) in vec4 inRect;
 layout(location = 1) in vec4 inCornerWidths;
@@ -45,16 +46,6 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
 #define SLICE_BOTTOM_LEFT 6
 #define SLICE_LEFT 7
 
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
 void main() {
   int slice_index = gl_VertexIndex / 6;
   int vert_index = gl_VertexIndex % 6;
@@ -96,7 +87,7 @@ void main() {
       break;
     }
 
-  rect = intersect (rect, push.clip_bounds);
+  rect = clip (rect);
   vec2 pos;
   if ((slice_index % 4) != 0 || (vert_index % 3) != 2)
     pos = rect.xy + rect.zw * offsets[vert_index];
index ce5e85e3dce516d82e033bb5e2dd1f906e25c462..50ce2a23af48ba8b03f5abe42d6ac63609551140 100644 (file)
Binary files a/gsk/resources/vulkan/border-clip-rounded.vert.spv and b/gsk/resources/vulkan/border-clip-rounded.vert.spv differ
index 8db91a58a4b48ace963eba702f98cf77d604f9d8..8e0fc8375e639963c8df62feb8f145fca7f1909a 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
 
 layout(location = 0) in vec4 inRect;
 layout(location = 1) in vec4 inCornerWidths;
@@ -45,16 +46,6 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
 #define SLICE_BOTTOM_LEFT 6
 #define SLICE_LEFT 7
 
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
 void main() {
   int slice_index = gl_VertexIndex / 6;
   int vert_index = gl_VertexIndex % 6;
@@ -96,7 +87,7 @@ void main() {
       break;
     }
 
-  rect = intersect (rect, push.clip_bounds);
+  rect = clip (rect);
   vec2 pos;
   if ((slice_index % 4) != 0 || (vert_index % 3) != 2)
     pos = rect.xy + rect.zw * offsets[vert_index];
index ce5e85e3dce516d82e033bb5e2dd1f906e25c462..50ce2a23af48ba8b03f5abe42d6ac63609551140 100644 (file)
Binary files a/gsk/resources/vulkan/border-clip.vert.spv and b/gsk/resources/vulkan/border-clip.vert.spv differ
diff --git a/gsk/resources/vulkan/clip.vert.glsl b/gsk/resources/vulkan/clip.vert.glsl
new file mode 100644 (file)
index 0000000..0dce1a0
--- /dev/null
@@ -0,0 +1,36 @@
+#include "constants.glsl"
+
+#ifndef _CLIP_
+#define _CLIP_
+
+vec4 intersect(vec4 a, vec4 b)
+{
+  a = vec4(a.xy, a.xy + a.zw);
+  b = vec4(b.xy, b.xy + b.zw);
+  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
+  if (any (greaterThanEqual (result.xy, result.zw)))
+    return vec4(0.0,0.0,0.0,0.0);
+  return vec4(result.xy, result.zw - result.xy);
+}
+
+#ifdef CLIP_ROUNDED_RECT
+vec4 clip(vec4 rect)
+{
+  /* rounded corner clipping is done in fragment shader */
+  return intersect(rect, push.clip_bounds);
+}
+#elif defined(CLIP_RECT)
+vec4 clip(vec4 rect)
+{
+  return intersect(rect, push.clip_bounds);
+}
+#elif defined(CLIP_NONE)
+vec4 clip(vec4 rect)
+{
+  return rect;
+}
+#else
+#error "No clipping define given. Need CLIP_NONE, CLIP_RECT or CLIP_ROUNDED_RECT"
+#endif
+
+#endif
index 985a174f97e5670519dad4dde1401a08c7699097..7f7a1e922644d69187c3ca36a9b4224077a5aeea 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
 
 layout(location = 0) in vec4 inRect;
 layout(location = 1) in vec4 inColor;
@@ -20,7 +21,9 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
                     vec2(1.0, 1.0) };
 
 void main() {
-  vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex];
+  vec4 rect = clip (inRect);
+
+  vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
   outPos = pos;
   outColor = inColor;
index 941189cf448a40eb49e27cd54a70dea7ac9687e6..daaf33aa22ef03465f0c6117a5af985f64954f68 100644 (file)
Binary files a/gsk/resources/vulkan/color-clip-rounded.vert.spv and b/gsk/resources/vulkan/color-clip-rounded.vert.spv differ
index 724cee1cdd358f6aa91cb521379cafe9be88c7af..a869b8a6253b3298a5ff192f3e7502e89fc742e7 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
 
 layout(location = 0) in vec4 inRect;
 layout(location = 1) in vec4 inColor;
@@ -18,18 +19,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
                     vec2(1.0, 0.0),
                     vec2(1.0, 1.0) };
 
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
 void main() {
-  vec4 rect = intersect(inRect, push.clip_bounds);
+  vec4 rect = clip (inRect);
 
   vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
index c07e45f6e3bca643b4b8c76b542dba670237f653..0b2711b2d1fafb954087b772fa9ea04c163f6a41 100644 (file)
Binary files a/gsk/resources/vulkan/color-clip.vert.spv and b/gsk/resources/vulkan/color-clip.vert.spv differ
index 1c7f0a43428e110a9914a9b377059f65144e1dec..3888b7e46059772c62039752e4ef75fd32ded64e 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
 
 layout(location = 0) in vec4 inRect;
 layout(location = 1) in vec4 inTexRect;
@@ -23,18 +24,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
                     vec2(1.0, 0.0),
                     vec2(1.0, 1.0) };
 
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
 void main() {
-  vec4 rect = intersect(inRect, push.clip_bounds);
+  vec4 rect = clip (inRect);
   vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
 
index 14b85f53ee5eeaa6100df3c236547139ff728f4d..f4951f653007b9ecf37bb1ac220e8a56dacaadf3 100644 (file)
Binary files a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv and b/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv differ
index 7f9b77840af7816725a8a60cffc17447abf31faf..6ae081715744333f6aff623881c91b0a8fe88ef8 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
 
 layout(location = 0) in vec4 inRect;
 layout(location = 1) in vec4 inTexRect;
@@ -22,18 +23,8 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
                     vec2(1.0, 0.0),
                     vec2(1.0, 1.0) };
 
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
 void main() {
-  vec4 rect = intersect(inRect, push.clip_bounds);
+  vec4 rect = clip (inRect);
   vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
 
index 84c384622efbb137f4efc0fcb0929b6fe2e9799d..20b615e67b8637b81599e794d7dae7015ab5934f 100644 (file)
Binary files a/gsk/resources/vulkan/color-matrix-clip.vert.spv and b/gsk/resources/vulkan/color-matrix-clip.vert.spv differ
index fd50e26f5589ab5449e8980e966ef39a22baf3ad..b574defc268cea813b92a1624d803ebc91509d37 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.vert.glsl"
 
 struct ColorStop {
   float offset;
@@ -50,7 +51,8 @@ get_gradient_pos (vec2 pos)
 }
 
 void main() {
-  vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex];
+  vec4 rect = clip (inRect);
+  vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
   outPos = pos;
   outGradientPos = get_gradient_pos (pos);
index 421516f7eff953b4344215f791bdd3b0c776ca32..9124ffbe413d8d5eaeb5736fcf248dd9cd7add95 100644 (file)
Binary files a/gsk/resources/vulkan/linear-clip-rounded.vert.spv and b/gsk/resources/vulkan/linear-clip-rounded.vert.spv differ
index 4ec7f2ead78b3d7afc760d7b373be735817d07ea..117642080effbc120d0340d1f2c59478c9126dde 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_RECT
+#include "clip.vert.glsl"
 
 struct ColorStop {
   float offset;
@@ -49,7 +50,8 @@ get_gradient_pos (vec2 pos)
 }
 
 void main() {
-  vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex];
+  vec4 rect = clip (inRect);
+  vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
   outGradientPos = get_gradient_pos (pos);
   outRepeating = inRepeating;
index e7d4cf6dac63ab615e347f5b0d5fc4afb2753823..74b823059e3674a319dbcf5685ab61ac6cbe9a5d 100644 (file)
Binary files a/gsk/resources/vulkan/linear-clip.vert.spv and b/gsk/resources/vulkan/linear-clip.vert.spv differ
index 7a55c61380f97e93bf8cd02217c1629427461622..5a7874c2b11d24e68ce4ddc7dcdba29424ae44df 100644 (file)
@@ -1,6 +1,7 @@
 #version 420 core
 
-#include "constants.glsl"
+#define CLIP_NONE
+#include "clip.vert.glsl"
 
 struct ColorStop {
   float offset;
@@ -39,16 +40,6 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
                     vec2(1.0, 0.0),
                     vec2(1.0, 1.0) };
 
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
 float
 get_gradient_pos (vec2 pos)
 {
@@ -59,7 +50,7 @@ get_gradient_pos (vec2 pos)
 }
 
 void main() {
-  vec4 rect = intersect(inRect, push.clip_bounds);
+  vec4 rect = clip (inRect);
   vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
   outGradientPos = get_gradient_pos (pos);
index f2b120f9e65b13e1af2bb55e5ed3d02f59729040..8a40b6d17d1963910392100bc46c183479e2a2f6 100644 (file)
Binary files a/gsk/resources/vulkan/linear.vert.spv and b/gsk/resources/vulkan/linear.vert.spv differ